cmake_minimum_required(VERSION 3.0.2)
project(co_detr_ros)

# 设置C++标准为17（支持filesystem）
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 查找依赖包
find_package(OpenCV REQUIRED)
find_package(CUDA REQUIRED)

# TensorRT路径
set(TENSORRT_ROOT "/data2/xd/TensorRT-8.5.1.7.Linux.x86_64-gnu.cuda-11.8.cudnn8.6/TensorRT-8.5.1.7")
set(TENSORRT_INCLUDE_DIRS ${TENSORRT_ROOT}/include)
set(TENSORRT_LIBRARIES ${TENSORRT_ROOT}/lib)

# 包含目录
include_directories(
    src/co_detr_ros/include
    ${OpenCV_INCLUDE_DIRS}
    ${TENSORRT_INCLUDE_DIRS}
    ${CUDA_INCLUDE_DIRS}
)

# 编译选项
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")

# 编译主检测器
add_executable(co_detr_detector
    src/co_detr_ros/src/co_detr_detector.cpp
    src/co_detr_ros/src/tensorrt_detector.cpp
)

target_link_libraries(co_detr_detector
    ${OpenCV_LIBRARIES}
    ${TENSORRT_LIBRARIES}/libnvinfer.so
    ${TENSORRT_LIBRARIES}/libnvonnxparser.so
    ${TENSORRT_LIBRARIES}/libnvinfer_plugin.so
    ${CUDA_LIBRARIES}
    dl
    pthread
)

# 编译引擎比较程序
add_executable(engine_comparison
    src/co_detr_ros/src/engine_comparison.cpp
    src/co_detr_ros/src/tensorrt_detector.cpp
)

target_link_libraries(engine_comparison
    ${OpenCV_LIBRARIES}
    ${TENSORRT_LIBRARIES}/libnvinfer.so
    ${TENSORRT_LIBRARIES}/libnvonnxparser.so
    ${TENSORRT_LIBRARIES}/libnvinfer_plugin.so
    ${CUDA_LIBRARIES}
    dl
    pthread
)

# 编译GridSample比较程序
add_executable(gridsample_comparison
    src/co_detr_ros/src/gridsample_comparison.cpp
)

target_link_libraries(gridsample_comparison
    ${OpenCV_LIBS}
    ${CUDA_LIBRARIES}
    ${TENSORRT_LIBRARIES}
    ${TENSORRT_ROOT}/lib/libnvinfer.so
    ${TENSORRT_ROOT}/lib/libnvonnxparser.so
    ${CUDA_TOOLKIT_ROOT_DIR}/lib64/libcudart.so
)

# 设置运行时库路径
set_target_properties(co_detr_detector PROPERTIES
    BUILD_WITH_INSTALL_RPATH TRUE
    INSTALL_RPATH "${TENSORRT_LIBRARIES}"
)

set_target_properties(engine_comparison PROPERTIES
    BUILD_WITH_INSTALL_RPATH TRUE
    INSTALL_RPATH "${TENSORRT_LIBRARIES}"
)
